package com.hailong.flink.rpc;

import akka.actor.ActorSystem;
import org.apache.flink.runtime.akka.AkkaUtils;
import org.apache.flink.runtime.rpc.akka.AkkaRpcService;
import org.apache.flink.runtime.rpc.akka.AkkaRpcServiceConfiguration;

/**
 * Created by yuanhailong on 2021/12/18.
 */
public class FlinkRPCServer {
    public static void main(String[] args) throws Exception {

        //step1 创建一个akkaSystem 系统
        //相当于Flink中的RPCService
        ActorSystem defaultActorSystem = AkkaUtils.createDefaultActorSystem();
        AkkaRpcService akkaRpcService = new AkkaRpcService(defaultActorSystem, AkkaRpcServiceConfiguration.defaultConfiguration());

        //step2 创建一个RpcEndpoint实例
        GetNowRpcEndpoint getNowRpcEndpoint = new GetNowRpcEndpoint(akkaRpcService);

        //step3 启动服务
        getNowRpcEndpoint.onStart();



        //打印akka服务器协议地址
        //akka.tcp://flink@192.168.0.101:61600/user/rpc/bfbe0525-0855-4ff2-816c-534ced593f19
        String address=getNowRpcEndpoint.getAddress();
        System.out.println(address);

        Thread.sleep(1000);

       /* GetNowGateway getNowGateway = akkaRpcService.connect(address, GetNowGateway.class).get();
        String now = getNowGateway.getNow();
        System.out.println(now);*/

        GetNowGateway selfGateway = getNowRpcEndpoint.getSelfGateway(GetNowGateway.class);
        String getNowResult1 = selfGateway.getNow();
        System.out.println(getNowResult1);


    }
}
